eststo clear
clear
if("`c(os)'"=="Windows"){
	local tableSaveDir = "Tables\"
	local plotSaveDir = "Plots\LOO\"
	local pythonSaveDir = "PythonScripts\"
}
else{
	local tableSaveDir = "Tables/"
	local plotSaveDir = "Plots/LOO/"
	local pythonSaveDir = "PythonScripts/"
}

if("`c(os)'"=="Windows"){
	local dataFile = "Tables\iv-loo.xlsx"
	local dataFileDiD = "Tables\did.xlsx"
}
else{
	
	local dataFile = "Tables/iv-loo.xlsx"
	local dataFileDiD = "Tables/did.xlsx"
}

set graphics off

//Load Data
local vmtSheet = "LOO-Spec2VMT"
local gasSheet = "LOO-Spec2GasUse"

import excel using "`dataFile'", sheet("`vmtSheet'") firstrow
label var Beta "LOO IV VMT Coefficient"
//Export histograms of the coefficient
hist Beta, name(ivVMT) freq graphregion(color(white)) plotregion(color(white))
graph export "`plotSaveDir'ivVMTHistogram.png", width(`widthPix') name(ivVMT) replace


clear
import excel using "`dataFile'", sheet("`gasSheet'") firstrow
label var Gamma "LOO Gas Use Coefficient"
//Export histograms of the coefficient
hist Gamma, name(ivGasUse) freq graphregion(color(white)) plotregion(color(white))
graph export "`plotSaveDir'ivGasUseHistogram.png", width(`widthPix') name(ivGasUse) replace

graph combine ivVMT ivGasUse, ycomm xcomm title("Histogram of Leave-One-Out IV Coefficients" "by  Outcome Variable") graphregion(color(white)) plotregion(color(white))
graph export "`plotSaveDir'ivHistogram.png", width(`widthPix') replace

//Diff-in-diff coefficients
clear 
import excel using "`dataFileDiD'", sheet("LOO-Spec1") firstrow
label var Eta "Spec. 1"
hist Eta, name(didSpec1) freq graphregion(color(white)) plotregion(color(white))
graph export "`plotSaveDir'didSpec1Histogram.png", width(`widthPix') name(didSpec1) replace

clear 
import excel using "`dataFileDiD'", sheet("LOO-Spec2") firstrow
label var Eta "Spec. 2"
hist Eta, name(didSpec2) freq graphregion(color(white)) plotregion(color(white))
graph export "`plotSaveDir'didSpec2Histogram.png", width(`widthPix') name(didSpec2) replace

clear 
import excel using "`dataFileDiD'", sheet("LOO-Spec3") firstrow
label var Eta "Spec. 3"
hist Eta, name(didSpec3) freq graphregion(color(white)) plotregion(color(white))
graph export "`plotSaveDir'didSpec3Histogram.png", width(`widthPix') name(didSpec3) replace

clear 
import excel using "`dataFileDiD'", sheet("LOO-Spec4") firstrow
label var Eta "Spec. 4"
hist Eta, name(didSpec4) freq graphregion(color(white)) plotregion(color(white))
graph export "`plotSaveDir'didSpec4Histogram.png", width(`widthPix') name(didSpec4) replace

graph combine didSpec1 didSpec2 didSpec3 didSpec4, ycomm xcomm title("Histogram of Leave-One-Out First-Stage Coefficients" "by  Outcome Variable") graphregion(color(white)) plotregion(color(white))
graph export "`plotSaveDir'didHistogram.png", width(`widthPix') replace


python script "`pythonSaveDir'outputLOO.py"


